<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('各销售渠道订单状态汇总')" />

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-form-label">创建时间</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="fpsj" />
                        </div>
                    </div>
                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal" data-type="reload" id="search_button"> 搜索 </a>
                    </div>
                    <div class="layui-inline inline-reset-btn">
                        <button type="reset" class="layui-btn layui-btn-primary" onclick="queryTable()" style="background-color: #40AFFE">重置</button>
                    </div>
                    <input type="hidden" id="fpsj_start" name="fpsj_start">
                    <input type="hidden" id="fpsj_end" name="fpsj_end">

                </form>
                <div class="moreBtn"><i class="layui-icon layui-icon-triangle-d" style="color: #1E9FFF;"></i></div>
                <div class="group-button" id="toolbar">
                    <a class="layui-btn layui-btn-sm layui-btn-normal  out-put" >
                        <i class="layui-icon">&#x1005;</i> 导出
                    </a>
                </div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body" >
                    <div class="pro">
                        <table id="table"></table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>
</body>

<div th:include="public/public_js::public_js"></div>
<script>
    //	回车查询
    document.onkeydown = function(event) {
        e = event ? event : (window.event ? window.event : null);
        if (e.keyCode == 13) {
            //执行的方法
            $('#search_button').click();
        }
    };
    $(function () {
        $(".moreBtn").on("click",function () {
            $(".moreSearch").toggle();
        })
    })
    layui.use(['list','layer','zzpUtils','jquery','laydate'],function () {
        var zzpUtils= layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;
        //创建时间开始
        laydate.render({
            elem: '#fpsj',
            type: 'date',
            range:'~',
            done: function(value, date, endDate){
                if(value!=null && value !=""){
                    var fpsj_start=value.toString().substring(0,value.toString().indexOf("~"));
                    var fpsj_end=value.toString().substring(value.toString().indexOf("~")+1);
                    $("#fpsj_start").val(Date.parse(new Date(fpsj_start)));
                    $("#fpsj_end").val(Date.parse(new Date(fpsj_end)));
                }else {
                    $("#fpsj_start").val("");
                    $("#fpsj_end").val("");
                }


                /*  alert(Date.parse(new Date($("#fpsj_start").val())));
                 alert("2018-8-1:"+Date.parse(new Date("2018-8-1")));
                 alert("2018-08-01:"+Date.parse(new Date("2018-08-01")));

                 console.log(value); //得到日期生成的值，如：2017-08-18
                 console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                 console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。*/
            }
        });
        // 年月选择器
        laydate.render({
            elem: '#test3',
            type: 'month',
        });
//        laydate.render({
//            elem: '#test5'
//            ,theme: '#20a0ff'
//        })
        //select2 查货品种类
//        $('.js-data-example-ajax').select2({
//            ajax: {
//                url: '/zxsswms/wmsgoodstype/getWmsGoodsTypeByHzId',
//                dataType: 'json',
//                type: 'POST',
//                contentType: "application/json",
//                data: function (params) {
//                    var query = {
//                        mc: params.term
//                    };
//                    return JSON.stringify(query);
//                },
//                processResults: function (data) {
//                    var arr= new Array();
//                    if(data){
//                        for (var i=0;i<data.length;i++){
//                            arr.push({id:data[i].mc,text:data[i].mc});
//                        }
//                    }
//                    console.log(arr);
//                    return {
//                        results: arr
//                    };
//                },
//                cache: true
//            },
//            language: "zh-CN",
//            placeholder: '请输入查询货品种类',
//            allowClear: true
//        });
        window.operateEvent ={
            "click .layui-btn-primary":function (e, value, row, index) {
                alert(row.mc);
            }
        }
        //查询list
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            pagination:true,
            striped: true,
            url: '/SalesChannelOrderStatusSummaryController/SalesChannel',
            columns: [{
                field: '',
                checkbox: true
            },{
                field: 'classA',
                title: '一级'
            },{
                field: 'classB',
                title: '二级'
            }, {
                field: 'classC',
                title: '三级'
            },{
                field: 'purpose',
                title: '用途'
            },{
                field: 'totalsales',
                title: '总销售额'
            },{
                field: 'ordernumber',
                title: '订单总量'
            },{
                field: 'totalnumber',
                title: '总支数'
            },{
                field: 'totalamount',
                title: '已发货金额',
                visible: true
            },{
                field: 'already',
                title: '已发货订单量',
                visible: true
            },{
                field: 'supportnumber',
                title: '支数',
                visible: true
            },{
                field: 'boxes',
                title: '箱数',
                visible: true
            },{
                field: 'unconsignment',
                title: '未发货金额',
                visible: true
            },{
                field: 'unshipped',
                title: '未发货订单量',
                visible: true
            },{
                field: 'unconsignmentcount',
                title: '未发货支数',
                visible: true
            },{
                field: 'refund',
                title: '退单金额',
                visible: true
            },{
                field: 'orderquantity',
                title: '退单订单量',
                visible: true
            },{
                field: 'regression',
                title: '退单支数',
                visible: true
            },{
                field: 'refund',
                title: '退单金额',
                visible: true
            }
            ],
            queryParams: function () {//查询条件
                return  zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            }
        });

        $(".inline-search-btn").on('click',function () {
            zzpUtils.refreshTable("#table");
        })
        // 导出
        /*$("#daochu").on('click', function () {
         var arr=[];
         var $rows = $table.bootstrapTable('getSelections');
         console.log('row', $rows);
         if ($rows.length >0) {
         arr = $.map($rows, function (row) {
         console.log(row.id);
         return row.id;
         })
         }
         var xhr = new XMLHttpRequest();
         xhr.open("POST", "http://localhost:8080/zxsswms/reports/getoutlibrary", true);
         xhr.responseType = "blob";
         xhr.setRequestHeader('Accept', 'application/json');
         xhr.setRequestHeader('Content-Type', 'application/json');
         xhr.setRequestHeader('Charset', 'utf-8');
         xhr.onload = function() {
         if (this.status == 200) {
         var name = xhr.getResponseHeader("Content-disposition");
         name=decodeURI(name);
         var filename = name.substring(20,name.length);
         var blob = new Blob([xhr.response], {type: 'text/xls'});
         var csvUrl = URL.createObjectURL(blob);
         var link = document.createElement('a');
         link.href = csvUrl;
         link.download = filename;
         link.click();
         }
         };
         /!*
         * 以下是将ids和对象拼接在一起
         * *!/
         var str=zzpUtils.getFormJson($("#searchForm"));
         var object2 = Object.assign({ids: arr}, str);
         console.log('object2', object2);
         /!*将条件查询和ids传到后台*!/
         xhr.send(JSON.stringify(
         object2
         ));
         })//导出结束*/

        /*顶部按钮导出 */
        $(".out-put").on('click', function () {
            console.log('导出');
            var arr=[];
            var $rows = $table.bootstrapTable('getSelections');
            if ($rows.length >0) {
                arr = $.map($rows, function (row) {
                    return row.cpid;
                })
            }
            /*
             * 以下是将ids和对象拼接在一起
             * */
            var obj = [];
            for(var i=0;i<arr.length;i++) {
                var person = {};
                person[i] = arr[i];
                obj.push(person);
            }
            var str=zzpUtils.getFormJson($("#searchForm"));
            var object2 = Object.assign({ids: arr}, str);
            /*将条件查询和ids传到后台*/
//            str.send();
            zzpUtils.outputXslx({
                url:"/SalesChannelOrderStatusSummaryController/SalesChannelExcel",
                data:JSON.stringify(object2)
            });
        })//导出结束


        /*顶部按钮多选启用*/
        $("#btn_qi").on('click', function () {
            var index = 0;
            var $rows = $table.bootstrapTable('getSelections');

        });
        // 重置
        window.queryTable = function () {
            location.reload();
        }

        //跳转生成添加页面
//        $(".add-btn").on('click',function () {
//            zzpUtils.dialog({
//                title:"新增货品",
//                type:2,
//                content: "/goods/toGoodAdd",
//                area: ['1350px', '630px'],
//                maxmin: true,
//                btn:[],
//                end: function () {//添加成功后刷新
//                    zzpUtils.refreshTable("#table");
//                }
//            });
//        })
    });
</script>
</html>